<template>
  <div class="topnav">
    <div class="topnav-ul">
      <el-scrollbar>
        <div class="topnav-ul_flex">
          <div
            class="item"
            :class="{ active: active === 0 }"
            @click="change(0)"
          >
            精选
            <span v-show="active === 0" class="line"></span>
          </div>
          <div
            v-for="item in datas.form.source_list"
            :key="item.value"
            class="item"
            :class="{ active: active === item.value }"
            @click="change(item.value)"
          >
            {{ item.label.substring(0, 5) }}
            <span v-show="active === item.value" class="line"></span>
          </div>
        </div>
      </el-scrollbar>
    </div>
    <div class="topnav-more">
      <img src="@/assets/images/template/h5/home_classification_icon.png" />
    </div>
    <!-- 删除组件 -->
    <slot name="deles" />
  </div>
</template>

<script>
export default {
  name: 'TopNav',
  props: {
    datas: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      active: 0
    }
  },
  methods: {
    change(index) {
      this.active = index
    }
  }
}
</script>

<style scoped lang="scss">
.topnav {
  height: 60px;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 15px;
  background: #ffffff;
  &-ul {
    & > ::v-deep.el-scrollbar {
      width: 100%;
      height: 100%;
      .el-scrollbar__wrap {
        width: 100%;
        height: 100%;
        overflow-y: hidden;
      }
      .el-scrollbar__view {
        width: 100%;
        height: 100%;
      }
    }
    flex: 1;
    min-width: 0;
    height: 100%;
    margin-right: 10px;
    .topnav-ul_flex {
      display: flex;
      align-items: center;
      height: 100%;
    }
    .item {
      font-size: 15px;
      font-weight: 400;
      color: #303133;
      line-height: 21px;
      margin-right: 24px;
      white-space: nowrap;
      transition: all 0.3s;
      position: relative;
      &.active {
        font-size: 16px;
        font-weight: 600;
      }
      .line {
        width: 20px;
        height: 4px;
        background: #5191ff;
        border-radius: 2px;
        position: absolute;
        left: 50%;
        bottom: -6px;
        transform: translateX(-50%);
      }
    }
    .item:last-child {
      margin-right: 0;
    }
  }
  .topnav-more {
    img {
      width: 20px;
      height: 20px;
    }
  }
}
</style>
